package com.zkw.gra.dynamic

/**
 * Created by Administrator on 2016/4/11 0011.
 * 通过简单的方式捕获异常
 * ?.
 */
class ProtectNullMain {
    def static map = [a:[b:[c:1]]]

    def static test(){
        assert map.a.b.c == 1
    }
    def static ifTest(){
        if(map && map.a && map.a.b){
            assert map.a.b.c == 1
        }
    }
    def static tryTest(){
        try {
            assert map.a.x.c ==1
        } catch (NullPointerException){
            println 'null pointer'
        }
    }
    def static easyest(){
        assert map?.a?.x?.c == 1
    }

    public static void main(String[] args) {
        test()
        ifTest()
        tryTest()
        easyest()
    }
}
